import { useStorage } from '@vueuse/core'
import { defineStore } from 'pinia'

import { GetConfig, SetConfig } from "../../wailsjs/go/main/App";

export const useToolsStore = defineStore('toolsStore', () => {
    const configValue = useStorage<Map<string,string>>('config-value', new Map())
  
   const GetConfigValue = async (node:string,name:string) => {
     if (window.runtime) {
       let res = await GetConfig(node,name)
       return res
     } else {
      return configValue.value.get(`${node}:${name}`)
     }
   }
   const SetConfigValue = async (node:string,name:string,value:string) => {
     if (window.runtime) {
       await SetConfig(node,name,value)
     } else {
      configValue.value.set(`${node}:${name}`,value)
     }
   }
  return {
    GetConfigValue,
    SetConfigValue
  }
})